package com.boruan.qq.zxgylibrary.utils;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import com.boruan.qq.zxgylibrary.ui.activities.ConfirmOrderActivity;
import com.boruan.qq.zxgylibrary.ui.activities.DrugPageDetailActivity;
import com.convenient.qd.core.base.arouter.ARouterConstant;
import com.convenient.qd.core.base.arouter.ARouterUtils;
import com.convenient.qd.core.bean.MenuTab;
import com.convenient.qd.core.user.UserDBHelper;
import com.convenient.qd.core.utils.CommonUtils;
import com.convenient.qd.module.user.widget.NoShiMingDialog;

/**
 * @Author: liweicai
 * @Date: 2020/3/31
 * @Description:
 */
public class NavigateUtils {
    private Activity activity;
    public NavigateUtils(Activity mActivity){
        this.activity = mActivity;
    }
    public void navigateConfirmOrderActivity(String shopId,int activityResult){
        if(UserDBHelper.getInstance().getFaceAuthFlag() != 1 || UserDBHelper.getInstance().getNameAuthFlag() != 1){
            showShiMingDialog();
            return;
        }
        Intent intent = new Intent(activity, ConfirmOrderActivity.class);
        intent.putExtra("shopId",shopId);
        if(activityResult > 0){
            activity.startActivityForResult(intent,activityResult);
        }
        activity.startActivity(intent);
    }

    private void judgeShiMingRen(){
        if(UserDBHelper.getInstance().getFaceAuthFlag() != 1){
            //未实人
            if(UserDBHelper.getInstance().getNameAuthFlag() != 1){
                //未实名 需要先实名再实人
                MenuTab menuTab = new MenuTab();
                menuTab.setAppId("");
                menuTab.setAndroidGoPage("");
                String path = ARouterConstant.ACTIVITY_IDCARD_HOME;
                Bundle bundle = new Bundle();
                bundle.putBoolean("isNeedShiRen",true);
                bundle.putSerializable("menuTab",menuTab);
                ARouterUtils.navigation(path,bundle);

            }else {
                //已实名 跳转实人
                MenuTab menuTab = new MenuTab();
                menuTab.setAppId("");
                menuTab.setAndroidGoPage("");
                String path = ARouterConstant.ACTIVITY_FACE_HOME;
                Bundle bundle = new Bundle();
                bundle.putSerializable("menuTab",menuTab);
                ARouterUtils.navigation(path,bundle);
            }
        }
    }

    private void showShiMingDialog(){
        final NoShiMingDialog noShiMingDialog = new NoShiMingDialog(activity);
        noShiMingDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialogInterface) {
                CommonUtils.backgroundAlpha(activity, 0.5f);
            }
        });
        noShiMingDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                CommonUtils.backgroundAlpha(activity, 1f);
            }
        });

        noShiMingDialog.setOnConfirmClickListener(new NoShiMingDialog.OnConfirmClickListener() {
            @Override
            public void onConFirmClick() {
                noShiMingDialog.dismiss();
                judgeShiMingRen();
            }
        });

        noShiMingDialog.setOnCancelClickListener(new NoShiMingDialog.OnCancelClickListener() {
            @Override
            public void onCancelClick() {
                noShiMingDialog.dismiss();
            }
        });

        noShiMingDialog.show();
        noShiMingDialog.setNotice("您好，请先完成实人，实名认证");
        noShiMingDialog.setBtnWidth(CommonUtils.dp2px(activity, 105));
        noShiMingDialog.setCancelContent("取消");
        noShiMingDialog.setConfirmContent("去认证");
    }

}
